const routes = [
  //   根目录重定向
  {
    path: '/',
    redirect: '/home',
  },
  {
    name: 'home',
    path: '/home',
    component: () => import('@/views/Home'),
  },
  {
    name: 'search',
    path: '/search',
    component: () => import('@/views/search'),
  },
  {
    path: '/detail/:id', //注意此处使用id占位
    component: () => import('@/views/Detail'),
  },
  {
    path: '/cart',
    component: () => import('@/views/ShopCart'),
  },
  {
    path: '/addcart_success',
    component: () => import('@/views/AddCartSuccess'),
  },
  {
    path: '/trade',
    component: () => import('@/views/Trade'),
    beforeEnter(to, from, next) {
      if (from.path === '/cart') next()
      else next('/home')
    },
  },
  {
    path: '/pay',
    component: () => import('@/views/Pay'),
    beforeEnter(to, from, next) {
      if (from.path === '/trade') next()
      else next('/home')
    },
  },
  {
    path: '/paySuccess',
    component: () => import('@/views/PaySuccess'),
  },
  // 登陆
  {
    name: 'login',
    path: '/login',
    component: () => import('@/views/Login'),
    meta: {
      isHiddenFooter: true, // 是否展示footer
      isHiddenSearch: true, // 是否展示搜索框
    },
  },
  // 注册
  {
    name: 'register',
    path: '/register',
    component: () => import('@/views/Register'),
    meta: {
      isHiddenFooter: true, // 是否展示footer
      isHiddenSearch: true, // 是否展示搜索框
    },
  },
  // 个人中心
  {
    path: '/center',
    component: () => import('@/views/Center'),
  },
]

export default routes
